package rpc

import (
	"log"
	"net"
	"net/rpc"
	"net/rpc/jsonrpc"
	"ocane/rpc/provide"
)


func InitRpc()  {
	arith := new(provide.Arith)
	rpc.Register(arith)
	addr, err := net.ResolveTCPAddr("tcp", ":8888")
	if err!=nil{
		panic(err)
	}
	tcp, err := net.ListenTCP("tcp", addr)
	if err!=nil{
		panic(err)
	}
	log.Println("rpc 服务启动成功")
	for{
		accept, err := tcp.Accept()
		if err!=nil{
			panic(err)
		}
		jsonrpc.ServeConn(accept)
	}
}

//init 初始化rpc服务端注册